package com.ujs.edu.demo.controller;

import com.ujs.edu.demo.dao.BcAdminMapper;
import com.ujs.edu.demo.dao.BcBooksMapper;
import com.ujs.edu.demo.dao.BcCollectMapper;
import com.ujs.edu.demo.dataobject.BcAdmin;
import com.ujs.edu.demo.dataobject.BcBooks;
import com.ujs.edu.demo.dataobject.BcCollect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @Autowired
    private BcAdminMapper bcAdminMapper;

    @Autowired
    private BcBooksMapper bcBooksMapper;

    @Autowired
    private BcCollectMapper bcCollectMapper;
//    @RequestMapping(path = "test")
//    @ResponseBody
//    public ModelAndView test() {
//        BcAdmin bcAdmin = bcAdminMapper.selectByPrimaryKey(1);
//        ModelAndView view = new ModelAndView();
//        view.addObject("admin", bcAdmin);
//        BcBooks bcBooks = bcBooksMapper.selectByPrimaryKey(1);
//        view.addObject("book", bcBooks);
//        view.setViewName("test");
//        return view;
//    }

    @RequestMapping(path = "test")
    @ResponseBody
    public ModelAndView test(){
        List<BcCollect>bcCollects=bcCollectMapper.selectByMany();
           ModelAndView view=new ModelAndView();

           List<BcBooks>books=new ArrayList<>();

           for (int i=0;i<bcCollects.size();i++){
               if (bcCollects.get(i).getMemberid()==14){
                   books.add(bcCollects.get(i).getBooks().get(0));
               }

           }

           view.addObject("collects",books);

           view.setViewName("personcenter");

           return view;
    }

//    @RequestMapping(path = "/test1")
//    public ModelAndView test1(){
//        BcAdmin bcAdmin=new BcAdmin();
//        bcAdmin.setAdminId(1);
//        bcAdmin.setSex(0);
//        bcAdmin.setRealname("hkhhdkj");
//        int a=bcAdminMapper.updateByPrimaryKey(bcAdmin);
//        System.out.println(a);
//        ModelAndView view=new ModelAndView();
//        view.addObject("admin",bcAdmin);
//        view.setViewName("test");
//        return view;
//    }
//
//    @RequestMapping(path = "/testupdate")
//    @ResponseBody
//    public String testupdate(){
//        BcAdmin bcAdmin=new BcAdmin();
//        bcAdmin.setAdminId(1);
//        bcAdmin.setRealname("熊宏杰");
//        bcAdmin.setSex(1);
//        bcAdmin.setMobile("18652743105");
//        int a=bcAdminMapper.updateByPrimaryKey(bcAdmin);
//        return "test"+a;
//    }
//
//    @RequestMapping(path = "/testselect")
//    @ResponseBody
//    public String testselect(){
//        BcAdmin password=bcAdminMapper.selectPassword(1);
//        return password.getPassword();
//    }
//
//    @RequestMapping(path = "testupdatepassword")
//    @ResponseBody
//    public String testupdatepassword(){
//        int a=bcAdminMapper.updatePassword("123",1);
//        return "success"+a;
//    }
}
